﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GamePlugin.Logics;
using GamePlugin.Logics.Core;
using GamePlugin.Logics.Data;

namespace GamePlugin.Controls
{
    /// <summary>
    /// Interaction logic for SearchInformation.xaml
    /// </summary>
    public partial class SearchInformation : UserControl
    {
        public SearchInformation()
        {
            InitializeComponent();

            Init();
        }

        private void Init()
        {
            Helper.FillCombox("職業", this.OccupationBox);
            Helper.FillCombox("裝備類型", this.EquipBox);
            Helper.FillCombox("物品稀有度", this.RarityBox);
        }

        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Workspace.Instance.SearchItem = e.NewValue as SearchItem;
            //Helper.GetMainWindow().searchInformation.UpdateComboxAndPropertyItem();
        }

        public void UpdateComboxAndPropertyItem()
        {
            if (Helper.CurrentDepth >= Helper.SearchItemArray.Length)
            {
                MessageBox.Show("Internal logic error, Helper.CurrentDepth is out of range.");
                return;
            }

            Helper.SearchItemArray[Helper.CurrentDepth].CopyFrom(Workspace.Instance.SearchItem);
            Helper.CurrentDepth++;

            SearchItem item = this.DataContext as SearchItem;
            if (item != null)
                Workspace.Instance.PropertyItemList.PropertyTreeRoot.TrySelectItem(item.PropertyName);
            this.UpdateCombox();

            Helper.CurrentDepth--;
            Workspace.Instance.SearchItem.CopyFrom(Helper.SearchItemArray[Helper.CurrentDepth]);
        }

        public void UpdateCombox()
        {
            SearchItem item = this.DataContext as SearchItem;
            if (item == null)
                return;

            Helper.FillCombox(Helper.GetName("裝備類型", item.EquipKind) + "物品類型", this.ItemBox);

            Helper.FillCombox(item.PropertyName, this.PropertyBox1);
            Helper.FillCombox(item.PropertyName, this.PropertyBox2);
            Helper.FillCombox(item.PropertyName, this.PropertyBox3);
            Helper.FillCombox(item.PropertyName, this.PropertyBox4);
            Helper.FillCombox(item.PropertyName, this.PropertyBox5);
            Helper.FillCombox(item.PropertyName, this.PropertyBox6);

            item.UpdateSearchInfoName();
        }
    }
}
